const validator = require('validator')

//用户注册验证
module .exports.validateCreateUser = (username,password,email)=>{
    let err = {}

    if(validator.isEmpty(username)){
        err.username = '用户名不能为空 !!!'
    }
    if(validator.isEmpty(password)){
        err.password = '密码不能为空 !!!'
    }
    if(validator.isEmpty(email)){
        err.email = 'email 不能为空 !!!'
    }
    if(!validator.isEmpty(email)&&!validator.isEmail(email)){
        err.email = 'email 格式不正确 !!!'
    }

    let validate = Object.keys(err).length < 1

    return {err,validate}
}

//用户登录验证
module .exports.validateUserLogin = (email,password)=>{
    let err = {}

    if(validator.isEmpty(email)){
        err.email = 'email 不能为空 !!!'
    }
    if(validator.isEmpty(password)){
        err.password = '密码不能为空 !!!'
    }
    
    if(!validator.isEmpty(email)&&!validator.isEmail(email)){
        err.email = 'email 格式不正确 !!!'
    }

    let validate = Object.keys(err).length < 1

    return {err,validate}
}